<template>
  <a-modal
    :width="600"
    :visible="open"
    :title="formTitle"
    @cancel="cancel"
  >
    <a-form-model ref="form" :model="form" layout="vertical">
      <a-row :gutter="32">
        <a-col :span="24">
          <a-form-model-item prop="newFileName">
            <a-input v-model="form.newFileName" placeholder="请输入文件名"/>
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>
    <template slot="footer">
      <a-button :disabled="disabled" @click="cancel">
        取消
      </a-button>
      <a-button type="primary" :disabled="disabled" @click="submitForm(true)">
        提交
      </a-button>
    </template>
  </a-modal>
</template>
<script>
import { createFile } from '@/api/dockerinsight/fileSystem'
export default {
  name: 'UploadForm',
  components: {
  },
  props: {
    currentPath: {
      type: String,
      required: true
    },
    ip: {
      type: String,
      required: true
    }
  },
  data () {
    return {
      open: false,
      formTitle: undefined,
      disabled: false,
      form: {}
    }
  },
  created () {
  },
  methods: {
    // 上传
    handleAdd () {
      this.reset()
      this.open = true
      this.formTitle = '新增普通文件'
    },
    // 重置表单
    reset() {
    },
    // 取消按钮
    cancel () {
      this.open = false
      this.reset()
    },
    // 提交
    submitForm (disabled) {
      this.disabled = disabled
      this.form.ip = this.ip
      this.form.currentPath = this.currentPath
      createFile(this.form).then(response => {
        this.disabled = true
        this.open = false
        this.$emit('ok')
        this.$emit('close')
      }).catch(error => {
        console.log(error)
        this.disabled = true
        this.open = false
      })
    }
  }
}
</script>
